package com.xiaojie.learn.util;

import java.io.*;

public class RemoveKeywordUtil {

    private static String KEYWORD = "-webkit-line-clamp: 5;";

    private static String SOURCE_PATH = "";
    private static String OUTPUT_PATH = "";

    public static void main(String[] args) throws IOException{
        File sourcePath = new File(SOURCE_PATH);
        File outputPath = new File(OUTPUT_PATH);
        if(!outputPath.exists()){
            outputPath.mkdirs();
        }
        listFile(sourcePath);
    }

    public static void listFile(File file) throws IOException{
        if (file.isDirectory()) {
            final File[] files = file.listFiles();
            for (File file0 : files) {
                listFile(file0);
            }
        }else{
            changeFile(file);
        }
    }

    public static void changeFile(File file) throws IOException {
        System.out.println(file.getName());
        if(!file.getName().endsWith("html")){
            return;
        }
        FileReader fileReader = new FileReader(file);
        BufferedReader bufferedReader = new BufferedReader(fileReader);

        File temp = new File(OUTPUT_PATH+File.separator+file.getName());
        FileWriter fileWriter = new FileWriter(temp);
        BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
        String str;
        while ((str = bufferedReader.readLine())!=null){
            if (str.contains(KEYWORD)){
                str = str.replace(KEYWORD,"");
            }
            bufferedWriter.write(str);
        }
        bufferedWriter.flush();
        bufferedWriter.close();
        fileWriter.close();
        bufferedReader.close();
        fileReader.close();
    }


}
